package demo;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String rootDirPath=scanner.next();
        File rootDir=new File(rootDirPath);
        if(!rootDir.isDirectory()){
            System.out.println("输入路径不合法");
            return;
        }
        String token=scanner.next();
        List<File> list=new ArrayList<>();
        dfs(rootDir,token,list);
        for(File file:list){
            System.out.println("输入'Y'确认删除文件");
            String in=scanner.next();
            if(in.equals("Y")){
                file.delete();
            }
        }
    }
    public static void dfs(File rootDir,String token,List<File> list){
        File[] files=rootDir.listFiles();
        for(File file:files){
            if(!file.isDirectory()){
                dfs(file,token,list);
            }else{
                if(file.getName().contains(token)){
                    list.add(file.getAbsoluteFile());
                }
            }
        }
    }
}
